#!/bin/bash

function authenticate {
    read -p "用户名:" username
    read -sp "密码:" password 
    echo 
    
    if [ "$username" = "root" ] && [ "$password" = "123456" ]; then
        return 0
    else
        return 1
    fi
}

#登录
echo "欢迎!"
authenticate

#检查
if [ $? -eq 0 ]; then
    echo "登录成功"
else
    echo "登录失败"
    exit 1
fi

#显示root用户命令提示符
while true ; do
    read -p "root [root n:] > " cmd
    if [ "$cmd" = "admin time" ]; then
       read -p "更改时间/日历(例如:YYYY-MM-DD HH:MM:SS)" new_time
       
       sudo date -s "$new_time"
       
       echo "修改后的时间:$new_time"
    elif [ "$cmd" = "new path" ]; then
       read -p "请输入添加文件/文件夹的昵称: " path
       
       if [ -f "$path" ]; then
          echo "发现同名文件"
       elif [ -d "$path" ]; then
          echo "发现同名文件夹"
       else
          mkdir -p "$path"
          echo "创建文件/文件夹完成"
       fi
    elif [ "$cmd" = "ls" ]; then
      ls
    elif [ "$cmd" = "cd" ]; then
      read -p "cd \?(请输入跳转的地址): " cd
      cd "$cd"
      echo "cd\: $cd "
    elif [ "$cmd" = "--help" ]; then
      echo "admin time"
      echo "install kali_linux"
      echo "kali /install"
      echo "new path"
      echo "cd"
      echo "ls"
      echo "install"
      echo "download"
      echo "--help"
    elif [ "$cmd" = "exit" ]; then
      break
    elif [ "$cmd" = "install kali_linux" ]; then
      exit "正在安装kali中"
      apt update && apt upgrade
      apt install git wget proot
      wget https://raw.githubusercontent.com/EXALAB/AnLinux-Resources/master/Scripts/Kali/kali.sh
      chmod +x kali.sh
      ./kali.sh
      echo "安装操作完成"
    elif [ "$cmd" = "kali /install" ]; then
      ./start-kali.sh
    elif [ "$cmd" = "install" ]; then
      read -p "请输入安装应用名称:" program_name
      download_link="https://downloadmonios.dxo.asia/Linux/$program_name"
      wget $download_link
      sudo apt-get install -f
      sudo dpks -i $progame_name
      rm $program_name
    elif [ "$cmd" = "download" ]; then
      cd bin
      bash install.sh
    elif [ "$cmd" = "bash" ]; then
      read -p "请输入想要运行的Linux程序(*.sh可运行)" bash_system
      bash $bash_system
    elif [ "$cmd" = "cd .." ]; then
      cd ..
    elif [ "$cmd" = "misver" ]; then
      cd bin
      bash misver.sh
    else
      echo "此函数运行时出错!"
    fi
done